﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 应用程序域
{
    /// <summary>
    /// 代理应用程序域的处理类
    /// </summary>
    public class ProxyAppDomain : MarshalByRefObject
    {

        public void CallBack()
        {

            AppDomain.CurrentDomain.UnhandledException += tmp_UnhandledException;
        }
        /// <summary>
        /// 异常隔离 
        /// http://www.cnblogs.com/huihui0630/archive/2010/06/30/1768387.html
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void tmp_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {

            //System.Windows.Application.Current.ex


            Console.WriteLine("引起一个末处理的异常........." + Thread.GetDomain().FriendlyName, e.ExceptionObject);


        }


        /// <summary>
        /// 引发一个异常
        /// </summary>
        public void Error()
        {
            //System.Threading.Thread thr = new System.Threading.Thread(() => {

            string s = System.Threading.Thread.GetDomain().FriendlyName;
            System.Threading.Thread.Sleep(100);
            //并行计算
            //System.Threading.Tasks.Parallel a;

            var aa = System.Threading.Tasks.TaskScheduler.Current;
            throw new NotSupportedException();
            // });

            // thr.Start();

        }

    }
}
